package com.example.administrator.yuejian_2.fragment;

import android.app.ProgressDialog;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.adapter.ClubRecentListAdapter;
import com.example.administrator.yuejian_2.adapter.ClubVideoAdapter;
import com.example.administrator.yuejian_2.bean.ClubListBean;
import com.example.administrator.yuejian_2.bean.ClubVideoBean;
import com.example.administrator.yuejian_2.interservice.ClubService;
import com.example.administrator.yuejian_2.interservice.Const;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class ClubVideoFragment extends Fragment {
    private RecyclerView recyclerView;
    private ClubVideoAdapter adapter;

    public ClubVideoFragment() {
        // Required empty public constructor
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        recyclerView = view.findViewById(R.id.club_video_RecyclerView);
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ClubService service = retrofit.create(ClubService.class);
        Call<List<ClubVideoBean>> call = service.clubvideolist();
        call.enqueue(new Callback<List<ClubVideoBean>>() {
            @Override
            public void onResponse(Call<List<ClubVideoBean>> call, Response<List<ClubVideoBean>> response) {
                if (getActivity() != null)
                    adapter = new ClubVideoAdapter(getActivity(),response.body());//adapter显示一条数据
                    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());//定义布局
                    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);//定义布局
                    recyclerView.setLayoutManager(layoutManager);//
                    recyclerView.setAdapter(adapter);//调用适配器
                    recyclerView.setItemAnimator(new DefaultItemAnimator());//调用item

            }

            @Override
            public void onFailure(Call<List<ClubVideoBean>> call, Throwable t) {
            }
        });


    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_club_video, container, false);
    }









}
